#ifndef __THREAD_H__
#define __THREAD_H__

#include <pthread.h>
#include <functional>
#include <string>

using std::function;
using std::string;

// 线程局部存储
extern __thread const char* name;

class Thread
// public : NonCopyable // 线程，对象语义
{
    using ThreadCallback = function<void()>;
public:
    Thread( ThreadCallback&& cb, const string& name = string() );
    ~Thread();

    void start();
    void join();

private:
    static void* threadFunc( void* );

private:
    pthread_t _thid;
    ThreadCallback _cb;
    string _name;
    bool _isRunning;

};

#endif
